package com.allwees.bs.module.mms.req.register;

import com.allwees.bs.core.modelbase.req.SignedReq;
import com.allwees.bs.core.modelbase.req.SmsVerifyCode;
import com.allwees.bs.core.modelbase.validate.ValidateItem;
import com.allwees.bs.module.mms.constant.EMmsSmsType;
import com.allwees.bs.module.mms.entity.RetailerApply;
import com.allwees.core.common.constant.EPlatform;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

@Data
@EqualsAndHashCode(callSuper = true)
public class RetailerRegisterVerifyReq extends SignedReq implements SmsVerifyCode {

    private EPlatform platform;

    private String mobile;

    private String email;

    private String password;

    private String verifyCode;

    @Override
    public ValidateItem[] getValidateItems() {
        return ArrayUtils.addAll(
                super.getValidateItems(),
                ValidateItem.of(platform == null, "platform 不能为空"),
                ValidateItem.of(StringUtils.isEmpty(email), "email 不能为空"),
                ValidateItem.of(StringUtils.isEmpty(mobile), "mobile 不能为空"),
                ValidateItem.of(StringUtils.isEmpty(verifyCode), "verifyCode 不能为空"),
                ValidateItem.of(StringUtils.isEmpty(password), "password 不能为空")
        );
    }

    @Override
    public String getSmsType() {
        return EMmsSmsType.RETAILER_REGISTER_APPLY.name();
    }

    @Override
    protected String signSeparator() {
        return platform.isApp() ? "_AS_" : "_PC_";
    }

    @Override
    protected Object[] signValues() {
        return new Object[]{platform.name(), mobile, email, password, time.getTime()};
    }

    public RetailerApply toEntity() {
        RetailerApply apply = new RetailerApply();
        apply.setEmail(email);
        apply.setMobile(mobile);
        return apply;
    }
}

